package pattern7.threadPool.demo;

import utils.PrintUtil;

/**
 * @创建人 liweijia
 * @创建时间 2022/7/30
 * @描述 程序的主要用途
 */
public class Main {
    public static void main(String[] args) throws InterruptedException {
        MyThreadPool pool = new MyThreadPool(5, 2);

        int index = 1;
        while (true) {
            PrintUtil.print("准备提交" + index);
            pool.submit(new MyTask(index));
            Thread.sleep(500);
            index++;
        }
    }

    static class MyTask implements Runnable {

        private final int index;

        MyTask(int index) {
            this.index = index;
        }

        @Override
        public void run() {
            PrintUtil.print("启动" + index);
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            PrintUtil.print("完成" + index);
        }
    }
}
